import adafruit_dht
import board

# DHT22 连接到 GPIO 4
dht_device = adafruit_dht.DHT22(board.D4)

try:
    temperature = dht_device.temperature
    humidity = dht_device.humidity
    print(f"温度: {temperature:.1f} C  湿度: {humidity:.1f}%")
except RuntimeError as error:
    print(error.args[0])
